package org.come.mouslisten;

import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.util.List;

import javax.swing.JList;

import com.updateNew.MyIsif;
import org.come.Jpanel.HallucinationJpanel;
import org.come.bean.ColorScheme;
import org.come.bean.Hallucination;
import org.come.entity.RoleSummoning;
import org.come.good.PetEquip;
import org.come.until.FormsManagement;

import com.tool.tcp.SpriteFactory;
import com.tool.tcpimg.UIUtils;

public class HallucinationMouslisten implements MouseListener, MouseMotionListener {
	private JList<String> listpet;// 召唤兽列表选中框
	private HallucinationJpanel hallucinationJpanel;// 召唤兽幻化面板
	private int type;

	public HallucinationMouslisten(int type,JList<String> listpet, HallucinationJpanel hallucinationJpanel) {
		this.type = type;
		this.listpet = listpet;
		this.hallucinationJpanel = hallucinationJpanel;
	}

	@Override
	public void mouseClicked(MouseEvent e) {
		// 打开了窗体
		if (e.isMetaDown()) {// 检测鼠标右键单击
			FormsManagement.HideForm(6);
		}
	}

	@Override
	public void mousePressed(MouseEvent e) {
		List<ColorScheme> lists = UIUtils.getColorScheme();
		if(type == 999) {
			if (e.getButton() == MouseEvent.BUTTON1) {// 左键点击
				hallucinationJpanel.initpets();
				HallucinationJpanel.selectColor = "";
				if (listpet.getSelectedIndex()>=0) {
					String petname = HallucinationJpanel.getListModel().get(listpet.getSelectedIndex());
					Hallucination item = HallucinationJpanel.dbHallucination.get(petname);
					RoleSummoning summoning = HallucinationJpanel.dbTujian.get(item.getOldpet());
					if (summoning!=null) {
						HallucinationJpanel.oldpart = SpriteFactory.createPart(summoning.getSummoningskin(), 5, 1, null);
					}
					HallucinationJpanel.newpart = SpriteFactory.createPart(item.getNewpet(), 5, 1, null);
					int adskin = PetEquip.getCJSID(Integer.parseInt(summoning.getSummoningid()));
					if (adskin != -1) {
						HallucinationJpanel.newpart.addPart(summoning.getHallucinationAdornPart(adskin,HallucinationJpanel.selectColor));
						for(int i=0;i<lists.size();i++) {
							int x = 0;
							int y = i;
							if(i>3) {
								y = i-4;
								x = 75;
							}
							HallucinationJpanel.labColorS[i].setBounds(468 +x, 307 + 28*y, 65, 25);
							HallucinationJpanel.labColorS[i].setText(lists.get(i).getName());
							HallucinationJpanel.labColorS[i].setVisible(true);
				    	}
					}else {
						for(int i=0;i<lists.size();i++) {
							HallucinationJpanel.labColorS[i].setVisible(false);
						}
					}
					HallucinationJpanel.showAll(item);
				}
			}
			// 等级
			if (listpet.getSelectedIndex() == -1) {
				return;
			}
		}else {
			Hallucination item = HallucinationJpanel.selecthallucination;
			RoleSummoning summoning = HallucinationJpanel.dbTujian.get(item.getOldpet());
			if (summoning!=null) {
				HallucinationJpanel.oldpart = SpriteFactory.createPart(summoning.getSummoningskin(), 5, 1, null);
			}
			HallucinationJpanel.newpart = SpriteFactory.createPart(item.getNewpet(), 5, 1, null);
			int adskin = PetEquip.getCJSID(Integer.parseInt(summoning.getSummoningid()));
			if (adskin != -1) {
				HallucinationJpanel.selectColor = "";
				for(int i=0;i<lists.size();i++) {
					if(i == type) {
						if (MyIsif.getStyle().equals("水墨UI")) {
							HallucinationJpanel.labColorS[i].setText("<html><body><font color='#f4f2eb'>" + lists.get(i).getName() + "</font><font color='#BBA54B'>√</body></html>");
						}else{
							HallucinationJpanel.labColorS[i].setText("<html><body><font color='#BBA54B'>" + lists.get(i).getName() + "</font><font color='#00EE00'>√</body></html>");
						}
						HallucinationJpanel.selectColor = lists.get(i).getValue();
					}else {
						HallucinationJpanel.labColorS[i].setText(lists.get(i).getName());
					}
				}
				HallucinationJpanel.newpart.addPart(summoning.getHallucinationAdornPart(adskin,HallucinationJpanel.selectColor));
			}
		}
	}

	@Override
	public void mouseReleased(MouseEvent e) {
		// TODO Auto-generated method stub
	}

	@Override
	public void mouseEntered(MouseEvent e) {
		// TODO Auto-generated method stub
	}

	@Override
	public void mouseExited(MouseEvent e) {
		// TODO Auto-generated method stub
//		ZhuFrame.getZhuJpanel().pettext();
	}

	@Override
	public void mouseDragged(MouseEvent e) {
		// TODO Auto-generated method stub

	}

	@Override
	public void mouseMoved(MouseEvent e) {
//		if (e.getY() / 22 < this.listpet.getModel().getSize()) {
//			TestPetJpanel.idx = this.listpet.locationToIndex(e.getPoint());
//			RoleSummoning pet = UserMessUntil.getPetListTable().get(TestPetJpanel.idx);
//			ZhuFrame.getZhuJpanel().creatpettext(pet);
//		}
	}
}
